#!/bin/bash

flink=/opt/module/flink-1.13.1/bin/flink
jar=/opt/gmall0823/gmall-realtime-1.0-SNAPSHOT.jar

# 定义数组, 存入需要启动的app的名字
apps=(
com.atguigu.realtime.app.dwd.DwdLogApp
com.atguigu.realtime.app.dwd.DwdDbApp
)

# 获取正在运行的所有app_name
running_apps=$($flink list 2>/dev/null | awk '/RUNNING/ {print $(NF-1)}')

# 遍历数组
for app in ${apps[*]} ; do
    app_name=$(echo $app | awk -F. '{print $NF}')

    # 判断要启动的app是否已经启动
    if [[ "${running_apps[@]}" =~ $app_name ]]; then
        echo "$app_name 已经启动, 无需重复启动"
    else
        echo "启动应用: $app_name"
        $flink run -d -c $app $jar
    fi
done


